<?php
function parse_back ($id, $back_id, $back, $myamount, $prev_amount, $acl, $key, $value, $chk_myamount)
{
    global $g_disk_name;
    global $g_betname_3or5;
    global $tbl_change;
    global $gametype;
    global $curruser;
    global $g_gametype_3d;
    $err = "";
    if ($back != $myamount[$key]["back{$back_id}"])
    {
        if ($acl < 5)
        {
            if ($back < $prev_amount[$key]["back{$back_id}"])
            {
                $err .= "<li>{$value} {$g_disk_name[$back_id]}退水 " . ( 100 - $back ) . " 不能大於上层 <b>" . ( 100 - $prev_amount[$key]["back{$back_id}"] ) . "</b>！</li>";
            }
        }
        else if ($back < $chk_myamount[$key]["back{$back_id}"])
        {
            $err .= "<li>{$value} {$g_disk_name[$back_id]}退水 " . ( 100 - $back ) . " 不能大於设限值 <b>" . ( 100 - $chk_myamount[$key]["back{$back_id}"] ) . "</b>！</li>";
        }
        if ($back < 0)
        {
            $err .= "<li>{$value} 退水不能大於 100！</li>";
        }
        else if (100 < $back)
        {
            $err .= "<li>{$value} 退水不能小於 0！</li>";
        }
        if ($err == "")
        {
            if ($gametype == 0)
            {
                $ikey = $key;
                $subid = 0;
                if (substr(strval($key), 0, 2) == "27")
                {
                    $ikey = 27;
                    $subid = $key - 270;
                }
                else if (substr(strval($key), 0, 2) == "36")
                {
                    $ikey = 36;
                    $subid = $key - 360;
                }
                $sql = "update amounts{$tbl_change} set back{$back_id}={$back} ,updateid=" . $curruser['id'] . " ,updatedt = '" . date("Y-m-d H:i:s", systime()) . "' where user_id={$id} and bettype = {$ikey} and subid = {$subid}";
                if ($myamount[$key]["back{$back_id}"] < $back)
                {
                    check_back($id, $back, $key, $back_id);
                }
                getdb($sql);
            }
            else if ($g_gametype_3d[$gametype]['type'] == 3)
            {
                $sql = "update amounts{$tbl_change} set back{$back_id}={$back} ,updateid=" . $curruser['id'] . " ,updatedt = '" . date("Y-m-d H:i:s", systime()) . "' where user_id={$id} and bettype = {$key} and subid = 0";
                if ($myamount[$key]["back{$back_id}"] < $back)
                {
                    check_back($id, $back, $key, $back_id);
                }
                getdb($sql);
            }
            else
            {
                $bettypeArr = explode("_", $key);
                $sql = "update amounts{$tbl_change} set back{$back_id}={$back} ,updateid=" . $curruser['id'] . " ,updatedt = '" . date("Y-m-d H:i:s", systime()) . "' where user_id={$id} and bettype = {$bettypeArr[0]} and subid = {$bettypeArr[1]}";
                if ($myamount[$key]["back{$back_id}"] < $back)
                {
                    check_back($id, $back, $key, $back_id);
                }
                getdb($sql);
            }
        }
    }
    return $err;
}

function check_back ($uid, $back, $bettype, $back_id)
{
    global $tbl_change;
    global $gametype;
    global $curruser;
    global $g_gametype_3d;
    if (is_array($uid))
    {
        $usrCmd = "select id,acl from k_user where prev_id in (" . implode(",", $uid) . ")";
    }
    else
    {
        $usrCmd = "select id,acl from k_user where prev_id=" . $uid;
    }
    $rs = getdb($usrCmd);
    $usrs = array();
    while (!$rs->eof)
    {
        $usrs[] = $rs->f[0];
        $rs->movenext();
    }
    if (count($usrs) == 0)
    {
        
    }
    else
    {
        if ($gametype == 0)
        {
            $ibettype = $bettype;
            $subid = 0;
            if (substr(strval($bettype), 0, 2) == "27")
            {
                $ibettype = 27;
                $subid = $bettype - 270;
            }
            else if (substr(strval($bettype), 0, 2) == "36")
            {
                $ibettype = 36;
                $subid = $bettype - 360;
            }
            $sqlCmd = "update amounts{$tbl_change} set back{$back_id}={$back} ,updateid=" . $curruser['id'] . " ,updatedt = '" . date("Y-m-d H:i:s", systime()) . "' where user_id IN (" . implode(",", $usrs) . ") and bettype =" . $ibettype . " and subid = {$subid} and back{$back_id}<{$back}";
            getdb($sqlCmd);
        }
        else if ($g_gametype_3d[$gametype]['type'] == 3)
        {
            $sqlCmd = "update amounts{$tbl_change} set back{$back_id}={$back} ,updateid=" . $curruser['id'] . " ,updatedt = '" . date("Y-m-d H:i:s", systime()) . "' where user_id IN (" . implode(",", $usrs) . ") and bettype =" . $bettype . " and subid = 0 and back{$back_id}<{$back}";
            getdb($sqlCmd);
        }
        else
        {
            $bettypeArr = explode("_", $bettype);
            $sqlCmd = "update amounts{$tbl_change} set back{$back_id}={$back} ,updateid=" . $curruser['id'] . " ,updatedt = '" . date("Y-m-d H:i:s", systime()) . "' where user_id IN (" . implode(",", $usrs) . ") and bettype = " . $bettypeArr[0] . " and subid = " . $bettypeArr[1] . " and back{$back_id}<{$back}";
            getdb($sqlCmd);
        }
        check_back($usrs, $back, $bettype, $back_id);
    }
}

function check_amount1 ($uid, $num, $bettype)
{
    global $tbl_change;
    global $gametype;
    global $curruser;
    global $g_gametype_3d;
    if (is_array($uid))
    {
        $usrCmd = "select id from k_user where prev_id in (" . implode(",", $uid) . ")";
    }
    else
    {
        $usrCmd = "select id from k_user where prev_id=" . $uid;
    }
    $rs = getdb($usrCmd);
    $usrs = array();
    while (!$rs->eof)
    {
        $usrs[] = $rs->f[0];
        $rs->movenext();
    }
    if (count($usrs) == 0)
    {
        
    }
    else
    {
        if ($gametype == 0)
        {
            $ibettype = $bettype;
            $subid = 0;
            if (substr(strval($bettype), 0, 2) == "27")
            {
                $ibettype = 27;
                $subid = $bettype - 270;
            }
            else if (substr(strval($bettype), 0, 2) == "36")
            {
                $ibettype = 36;
                $subid = $bettype - 360;
            }
            $sqlCmd = "update amounts" . $tbl_change . " set amount1=" . $num . " ,updateid=" . $curruser['id'] . " ,updatedt = '" . date("Y-m-d H:i:s", systime()) . "' where user_id IN (" . implode(",", $usrs) . ") and bettype=" . $ibettype . " and subid= {$subid} and amount1>" . $num;
            getdb($sqlCmd);
        }
        else if ($g_gametype_3d[$gametype]['type'] == 3)
        {
            $sqlCmd = "update amounts" . $tbl_change . " set amount1=" . $num . " ,updateid=" . $curruser['id'] . " ,updatedt = '" . date("Y-m-d H:i:s", systime()) . "' where user_id IN (" . implode(",", $usrs) . ") and bettype=" . $bettype . " and subid= 0 and amount1>" . $num;
            getdb($sqlCmd);
        }
        else
        {
            $bettypeArr = explode("_", $bettype);
            $sqlCmd = "update amounts" . $tbl_change . " set amount1=" . $num . " ,updateid=" . $curruser['id'] . " ,updatedt = '" . date("Y-m-d H:i:s", systime()) . "' where user_id IN (" . implode(",", $usrs) . ") and bettype=" . $bettypeArr[0] . " and subid=" . $bettypeArr[1] . " and amount1>" . $num;
            getdb($sqlCmd);
        }
        check_amount1($usrs, $num, $bettype);
    }
}

function check_amount2 ($uid, $num, $bettype)
{
    global $tbl_change;
    global $gametype;
    global $curruser;
    global $g_gametype_3d;
    if (is_array($uid))
    {
        $usrCmd = "select id from k_user where prev_id in (" . implode(",", $uid) . ")";
    }
    else
    {
        $usrCmd = "select id from k_user where prev_id=" . $uid;
    }
    $rs = getdb($usrCmd);
    $usrs = array();
    while (!$rs->eof)
    {
        $usrs[] = $rs->f[0];
        $rs->movenext();
    }
    if (count($usrs) == 0)
    {
        
    }
    else
    {
        if ($gametype == 0)
        {
            $ibettype = $bettype;
            $subid = 0;
            if (substr(strval($bettype), 0, 2) == "27")
            {
                $ibettype = 27;
                $subid = $bettype - 270;
            }
            else if (substr(strval($bettype), 0, 2) == "36")
            {
                $ibettype = 36;
                $subid = $bettype - 360;
            }
            $sqlCmd = "update amounts" . $tbl_change . " set amount2=" . $num . " ,updateid=" . $curruser['id'] . " ,updatedt = '" . date("Y-m-d H:i:s", systime()) . "' where user_id IN (" . implode(",", $usrs) . ") and bettype=" . $ibettype . " and subid= {$subid} and amount2>" . $num;
            getdb($sqlCmd);
        }
        else if ($g_gametype_3d[$gametype]['type'] == 3)
        {
            $sqlCmd = "update amounts" . $tbl_change . " set amount2=" . $num . " ,updateid=" . $curruser['id'] . " ,updatedt = '" . date("Y-m-d H:i:s", systime()) . "' where user_id IN (" . implode(",", $usrs) . ") and bettype=" . $bettype . " and subid= 0 and amount2>" . $num;
            getdb($sqlCmd);
        }
        else
        {
            $bettypeArr = explode("_", $bettype);
            $sqlCmd = "update amounts" . $tbl_change . " set amount2=" . $num . " ,updateid=" . $curruser['id'] . " ,updatedt = '" . date("Y-m-d H:i:s", systime()) . "' where user_id IN (" . implode(",", $usrs) . ") and bettype=" . $bettypeArr[0] . " and subid=" . $bettypeArr[1] . " and amount2>" . $num;
            getdb($sqlCmd);
        }
        check_amount2($usrs, $num, $bettype);
    }
}

if (!defined("IN_OP"))
{
    exit("You can't access this file directly...");
}
$id = intval($_GET['id']);
if ($id == 0)
{
    exit("You not input id!");
}
$gametype = intval(getvar("gametype"));
if($gametype==0 && !$g_init_mode_6h) $gametype=12;

$chkGametype = chkGametype($gametype);
$othertext = "";


$tbl_change = $gametype ? "_" . $g_gametype_3d[$gametype]['en'] : "";
switch ($chkGametype)
{
    case 0 :
        $ui = new UI(true);
        include( "member/news.php" );
        $show3D3S = 0;
        $change_betname = $g_betname;
        $i = 2;
        while ($i < 6)
        {
            $change_betname["27" . $i] = "连肖" . $i;
            $change_betname["36" . $i] = "连尾" . $i;
            ++$i;
        }
        unset($change_betname[27]);
        unset($change_betname[36]);
       // unset($change_betname[365]);
        $g_betname_3or5 = $change_betname;
        $listArr01 = array(1, 2, 3, 5, 6, 28, 30, 15, 16, 35, 47);
        $othertext .= "<font color=\"red\">";
        $othertext .= "&#12288;&#12288;※ 特码、正码、正码特单项限额为单一号码！";
        $othertext .= "<br>&#12288;&#12288;※ 连尾中与不中共用退水及限额！";
        $othertext .= "</font>";
        break;
    case 1 :
    case 2 :
    case 3 :
	case 4 :
        include_once( "class_3d/CheckMode_3d.php" );
        $chk = new CheckMode_3d($curruser['acl'], 1, $gametype);
        $chk->checkShow3dPage();
        $show3D3S = $chk->show3D3S;
        unset($chk);
        $ui = new UI_3D(true);
        $jslink = "<script language=\"JScript.Encode\" src=\"site.js\"></script>" . ( "<script language=\"VBScript.Encode\" src=\"site.vbs\"></script>" ) . "<script src=\"core/tpl/k2/jquery-1.4.2.min.js\"></script>";
        $ui->set("jslink", $jslink);
        $ui->header();
        $ui->showNews3D($curruser['acl']);
        if ($g_gametype_3d[$gametype]['type'] < 3)
        {
            $g_betname_3or5 = judge_type($gametype);
            /*foreach ($g_onlyN5Arr as $key => $value)
            {
                $listArr01[] = $value . "_0";
            }*/
            foreach ($g_2face_3d as $key => $value)
            {
                $listArr01[] = $value . "_0";
            }
        }
        else if ($g_gametype_3d[$gametype]['type'] == 3)
        {
            $g_betname_3or5 = $g_betname_5h[$gametype];
            $listArr01 = $g_2face_5h[$gametype];
        }
		elseif($gametype==25 || $gametype==26)
		{
			foreach ($_sb_Arr as $key => $value)
            {
                $g_betname_3or5[$key."_0"] = $value;
            }

			$listArr01 = $g_2face_5h;
		}
        break;
    default :
        exit("error gametype");
}
if (isset($_SESSION['subaccount']) && $curruser['acl'] < 255)
{
    $ui->showErrorPage("你是子帐号，不能执行这个功能！");
    exit();
}
$tpl = new Template2();
$conf = new Config();
$chkFastStr = SubAccountRight($curruser, 2) != 2 ? "disabled" : "";
$u = get_user($id);
if (!$u)
{
    diemsg(L_ERRMEMID);
}
$acl = $u['acl'];
if ($u['acl'] == 1)
{
    header("Location: op.php?op=agent&fp=amount2_3d&gametype={$gametype}&id={$id}");
    exit();
}
if ($curruser['acl'] <= $acl)
{
    diemsg("你没有权限存取！");
}
$users = "";
if ($curruser['acl'] < 255)
{
    $users = getuserlist($curruser['id'], $acl);
    if ($users == "")
    {
        diemsg("不是你的会员！");
    }
    $userArrTemp = explode(",", $users);
    if (!in_array($id, $userArrTemp))
    {
        diemsg("不是你的会员！");
    }
}
$psen_edit_mod = 1;
$nextDateFlag = false;
$startbet = $conf->get("startbet{$tbl_change}");
$stopbet = $conf->get("stopbet{$tbl_change}");
if ($stopbet < $startbet)
{
    $nextDateFlag = true;
}
$now = date("Hi");
$todayTime = systime();
$today = date("Y-m-d");
if ($nextDateFlag)
{
    if ($startbet <= $now)
    {
        $psen_edit_mod = 0;
    }
    else
    {
        if ($now < $stopbet)
        {
            $today = date("Y-m-d", strtotime("-1 day"));
            $psen_edit_mod = 0;
        }
    }
}
else if ($startbet <= $now && $now <= $stopbet)
{
    $psen_edit_mod = 0;
}
$open = $today;
$users = GetUserList($id);
switch ($chkGametype)
{
    case 0 :
        $amountField = "amount";
        break;
    case 1 :
        $amountField = "amount_3d";
        break;
    case 2 :
    case 3 :
        $amountField = "amount_3s1";
        break;
}
if ($users != "")
{
    $sql = "SELECT a.id FROM bet{$tbl_change} a LEFT JOIN lotto{$tbl_change} b ON (b.id = a.lotto_id)" . " WHERE b.open = '{$open}'" . " AND a.rame != 2" . " AND a.user_id IN ({$users})" . " LIMIT 0,1";
    $rs = getdb($sql);
    if ($rs->eof)
    {
        $psen_edit_mod = 1;
    }
    $rs->close();
}
else
{
    $psen_edit_mod = 1;
}
$edit_back_mode = $psen_edit_mod ? 0 : 1;
$prev_amount = false;
$chk_myamount = GetAmountSetting(1, $gametype, 0);
if ($u['acl'] < 5)
{
    $prev_amount = GetAmountSetting($u['prev_id'], $gametype, 1);
}
else if ($u['acl'] == 5)
{
    $prev_amount = $chk_myamount;
}
$myamount = GetAmountSetting($id, $gametype, 1);
if ($myamount == false)
{
    CreateAmount($id, $gametype);
    $myamount = GetAmountSetting($id, $gametype, 0);
}
$editBackFlag = $edit_back_mode ? false : true;
if (ispost() && SubAccountRight($curruser, 2) == 2)
{
    $chkFast = intval(getvar("chkFast"));
    if ($chkFast == 1)
    {
        $save_error = false;
        $errall = "";
        if ($u['acl'] == 5)
        {
            foreach ($g_betname_3or5 as $key => $value)
            {
                $err = "";
                $amount1 = $prev_amount[$key][1];
                $amount2 = $prev_amount[$key][2];
                if ($amount1 != $myamount[$key][1] || $amount2 != $myamount[$key][2] || $prev_amount[$key]['back1'] != $myamount[$key]['back1'] || $prev_amount[$key]['back2'] != $myamount[$key]['back2'] || $prev_amount[$key]['back3'] != $myamount[$key]['back3'] || $prev_amount[$key]['back4'] != $myamount[$key]['back4'])
                {
                    $sql = "UPDATE amounts{$tbl_change} SET " . " amount1={$amount1}, amount2={$amount2}";
                    if ($editBackFlag)
                    {
                        $back1 = $prev_amount[$key]['back1'];
                        $back2 = $prev_amount[$key]['back2'];
                        $back3 = $prev_amount[$key]['back3'];
                        $back4 = $prev_amount[$key]['back4'];
                        $sql .= " , back1={$back1}, back2={$back2}, back3={$back3}, back4={$back4} ";
                    }
                    if ($gametype == 0)
                    {
                        $ikey = $key;
                        $subid = 0;
                        if (substr(strval($key), 0, 2) == "27")
                        {
                            $ikey = 27;
                            $subid = $key - 270;
                        }
                        else if (substr(strval($key), 0, 2) == "36")
                        {
                            $ikey = 36;
                            $subid = $key - 360;
                        }
                        $sql .= ",updateid=" . $curruser['id'] . " ,updatedt = '" . date("Y-m-d H:i:s", systime()) . "' WHERE user_id = {$id} AND bettype = {$ikey} AND subid = {$subid}";
                        getdb($sql);
                    }
                    else if ($g_gametype_3d[$gametype]['type'] == 3)
                    {
                        $sql .= ",updateid=" . $curruser['id'] . " ,updatedt = '" . date("Y-m-d H:i:s", systime()) . "' WHERE user_id = {$id} AND bettype = {$key} AND subid = 0";
                        getdb($sql);
                    }
                    else
                    {
                        $bettypeArr = explode("_", $key);
                        $sql .= ",updateid=" . $curruser['id'] . " ,updatedt = '" . date("Y-m-d H:i:s", systime()) . "' WHERE user_id = {$id} AND bettype = {$bettypeArr[0]} AND subid = {$bettypeArr[1]}";
                        getdb($sql);
                    }
                    if ($amount1 != $myamount[$key][1])
                    {
                        check_amount1($id, $amount1, $key);
                    }
                    if ($amount2 != $myamount[$key][2])
                    {
                        check_amount2($id, $amount2, $key);
                    }
                    if ($editBackFlag)
                    {
                        if ($back1 != $myamount[$key]['back1'])
                        {
                            check_back($id, $back1, $key, 1);
                        }
                        if ($back2 != $myamount[$key]['back2'])
                        {
                            check_back($id, $back2, $key, 2);
                        }
                        if ($back3 != $myamount[$key]['back3'])
                        {
                            check_back($id, $back3, $key, 3);
                        }
                        if ($back4 != $myamount[$key]['back4'])
                        {
                            check_back($id, $back4, $key, 4);
                        }
                    }
                }
            }
        }
        else
        {
            foreach ($g_betname_3or5 as $key => $value)
            {
                $err = "";
                $amount1 = $prev_amount[$key][1];
                $amount2 = $prev_amount[$key][2];
                if ($amount1 != $myamount[$key][1] || $amount2 != $myamount[$key][2] || $prev_amount[$key]['back1'] != $myamount[$key]['back1'] || $prev_amount[$key]['back2'] != $myamount[$key]['back2'] || $prev_amount[$key]['back3'] != $myamount[$key]['back3'] || $prev_amount[$key]['back4'] != $myamount[$key]['back4'])
                {
                    $sql = "UPDATE amounts{$tbl_change} SET " . " amount1={$amount1}, amount2={$amount2}";
                    if ($editBackFlag)
                    {
                        $back1 = $prev_amount[$key]['back1'];
                        $back2 = $prev_amount[$key]['back2'];
                        $back3 = $prev_amount[$key]['back3'];
                        $back4 = $prev_amount[$key]['back4'];
                        $sql .= ", back1={$back1}, back2={$back2}, back3={$back3}, back4={$back4} ";
                    }
                    if ($gametype == 0)
                    {
                        $ikey = $key;
                        $subid = 0;
                        if (substr(strval($key), 0, 2) == "27")
                        {
                            $ikey = 27;
                            $subid = $key - 270;
                        }
                        else if (substr(strval($key), 0, 2) == "36")
                        {
                            $ikey = 36;
                            $subid = $key - 360;
                        }
                        $sql .= ",updateid=" . $curruser['id'] . " ,updatedt = '" . date("Y-m-d H:i:s", systime()) . "' WHERE user_id = {$id} AND bettype = {$ikey} AND subid = {$subid}";
                        getdb($sql);
                    }
                    else if ($g_gametype_3d[$gametype]['type'] == 3)
                    {
                        $sql .= ",updateid=" . $curruser['id'] . " ,updatedt = '" . date("Y-m-d H:i:s", systime()) . "' WHERE user_id = {$id} AND bettype = {$key} AND subid = 0";
                        getdb($sql);
                    }
                    else
                    {
                        $bettypeArr = explode("_", $key);
                        $sql .= ",updateid=" . $curruser['id'] . " ,updatedt = '" . date("Y-m-d H:i:s", systime()) . "' WHERE user_id = {$id} AND bettype = {$bettypeArr[0]} AND subid = {$bettypeArr[1]}";
                        getdb($sql);
                    }
                    if ($amount1 != $myamount[$key][1])
                    {
                        check_amount1($id, $amount1, $key);
                    }
                    if ($amount2 != $myamount[$key][2])
                    {
                        check_amount2($id, $amount2, $key);
                    }
                    if ($editBackFlag)
                    {
                        if ($back1 != $myamount[$key]['back1'])
                        {
                            check_back($id, $back1, $key, 1);
                        }
                        if ($back2 != $myamount[$key]['back2'])
                        {
                            check_back($id, $back2, $key, 2);
                        }
                        if ($back3 != $myamount[$key]['back3'])
                        {
                            check_back($id, $back3, $key, 3);
                        }
                        if ($back4 != $myamount[$key]['back4'])
                        {
                            check_back($id, $back4, $key, 4);
                        }
                    }
                }
            }
        }
        $myamount = GetAmountSetting($id, $gametype, 1);
        $chkFastStr = "checked=\"true\"";
    }
    else
    {
        $save_error = false;
        $errall = "";
        foreach ($g_betname_3or5 as $key => $value)
        {
            if (!isset($_POST["amount1{$key}"]) || !isset($_POST["amount2{$key}"]) || !isset($_POST["back{$key}1"]) || !isset($_POST["back{$key}2"]) || !isset($_POST["back{$key}3"]) || !isset($_POST["back{$key}4"]))
            {
                $save_error = true;
                $errall = "<br><font color='red'><ul>欲修改之退水与限额资料不齐全，更新失败</ul></font>";
                $tpl->set("err", $errall);
            }
            if (!$save_error)
            {
                $err = "";
                $amount1 = intval($_POST["amount1{$key}"]);
                $amount2 = intval($_POST["amount2{$key}"]);
                if ($gametype == 0 && array_key_exists($key, $g_bettype_ab) && $key != $g_bettype_ab[$key][1])
                {
                    if ($amount1 == 0 || $amount2 == 0)
                    {
                        $amount1 = 0;
                        $amount2 = 0;
                    }
                    else if (0 < $amount1 && 0 < $amount2)
                    {
                        $amount1 = intval(getvar("amount1" . $g_bettype_ab[$key][1]));
                        $amount2 = intval(getvar("amount2" . $g_bettype_ab[$key][1]));
                    }
                }
                $back1 = 100 - round(floatval($_POST["back{$key}1"]), 2);
                $back2 = 100 - round(floatval($_POST["back{$key}2"]), 2);
                $back3 = 100 - round(floatval($_POST["back{$key}3"]), 2);
                $back4 = 100 - round(floatval($_POST["back{$key}4"]), 2);
                if ($amount1 < 0)
                {
                    $amount1 = $amount2 * 0.5;
                }
                if ($amount2 < $amount1)
                {
                    $amount1 = $amount2;
                }
                if ($amount1 != $myamount[$key][1] || $amount2 != $myamount[$key][2])
                {
                    if ($u['enabled'] == 1)
                    {
                        if ($prev_amount[$key][2] < $amount2)
                        {
                            $err .= "<li>{$value} 额度超过上层可用限额 <b>{$prev_amount[$key][2]}</b>！</li>";
                        }
                        if ($prev_amount[$key][1] < $amount1)
                        {
                            $err .= "<li>{$value} 额度超过上层单注限额 <b>{$prev_amount[$key][1]}</b>！</li>";
                        }
                    }
                    if ($err == "")
                    {
                        if ($gametype == 0)
                        {
                            $ikey = $key;
                            $subid = 0;
                            if (substr(strval($key), 0, 2) == "27")
                            {
                                $ikey = 27;
                                $subid = $key - 270;
                            }
                            else if (substr(strval($key), 0, 2) == "36")
                            {
                                $ikey = 36;
                                $subid = $key - 360;
                            }
                            $sql = "update amounts{$tbl_change} set amount1={$amount1}, amount2={$amount2} ,updateid=" . $curruser['id'] . " ,updatedt = '" . date("Y-m-d H:i:s", systime()) . "' where user_id={$id} and bettype = {$ikey} and subid = {$subid}";
                            getdb($sql);
                        }
                        else if ($g_gametype_3d[$gametype]['type'] == 3)
                        {
                            $sql = "update amounts{$tbl_change} set amount1={$amount1}, amount2={$amount2} ,updateid=" . $curruser['id'] . " ,updatedt = '" . date("Y-m-d H:i:s", systime()) . "' where user_id={$id} and bettype = {$key} and subid = 0";
                            getdb($sql);
                        }
                        else
                        {
                            $bettypeArr = explode("_", $key);
                            $sql = "update amounts{$tbl_change} set amount1={$amount1}, amount2={$amount2} ,updateid=" . $curruser['id'] . " ,updatedt = '" . date("Y-m-d H:i:s", systime()) . "' where user_id={$id} and bettype = {$bettypeArr[0]} and subid = {$bettypeArr[1]}";
                            getdb($sql);
                        }
                        if ($amount1 != $myamount[$key][1])
                        {
                            check_amount1($id, $amount1, $key);
                        }
                        if ($amount2 != $myamount[$key][2])
                        {
                            check_amount2($id, $amount2, $key);
                        }
                    }
                    $errall .= $err;
                    $err = "";
                }
                if ($editBackFlag)
                {
                    $errall .= parse_back($id, 1, $back1, $myamount, $prev_amount, $acl, $key, $value, $chk_myamount);
                    $errall .= parse_back($id, 2, $back2, $myamount, $prev_amount, $acl, $key, $value, $chk_myamount);
                    $errall .= parse_back($id, 3, $back3, $myamount, $prev_amount, $acl, $key, $value, $chk_myamount);
                    $errall .= parse_back($id, 4, $back4, $myamount, $prev_amount, $acl, $key, $value, $chk_myamount);
                }
            }
        }
        if (!$save_error)
        {
            if ($errall != "")
            {
                $errall = "<font color='red'><ul>{$errall}</ul></font><br>";
            }
            $tpl->set("err", $errall);
            if ($u['acl'] < 5)
            {
                $prev_amount = GetAmountSetting($u['prev_id'], $gametype, 0);
            }
            $myamount = GetAmountSetting($id, $gametype, 1);
        }
    }
}
$tpl->load("main", "amount_3d.htm");
$op_val = array(1 => "agent", 2 => "genagent", 3 => "shareowner", 4 => "subsidary", 5 => "admin");
$fp_val = array(1 => "member", 2 => "agent", 3 => "genagent", 4 => "shareowner", 5 => "subsidary");
$name_val = array(1 => "会员", 2 => "代理", 3 => "总代理", 4 => "股东", 5 => "大股东");
$funlist = "<a href=\"?op={$op_val[$acl]}&fp={$fp_val[$acl]}&gametype={$gametype}&cmd=list&enabled=1\">启用列表</a>" . "<a href=\"?op={$op_val[$acl]}&fp={$fp_val[$acl]}&gametype={$gametype}&cmd=list&enabled=0\">停用列表</a>" . "<a href=\"?op={$op_val[$acl]}&fp={$fp_val[$acl]}&gametype={$gametype}&cmd=edit&id={$id}\">回编辑页</a>";
$tbdList01 = "";
$tbdList02 = "";
$total = 0;
$tbdList = "";
if ($edit_back_mode)
{
    $readonly = " readonly";
}
else
{
    $readonly = "";
}
foreach ($g_betname_3or5 as $key => $value)
{
    if ($myamount[$key]['back1'] == 0)
    {
        $myamount[$key]['back1'] = 100;
    }
    if ($myamount[$key]['back2'] == 0)
    {
        $myamount[$key]['back2'] = 100;
    }
    if ($myamount[$key]['back3'] == 0)
    {
        $myamount[$key]['back3'] = 100;
    }
    if ($myamount[$key]['back4'] == 0)
    {
        $myamount[$key]['back4'] = 100;
    }
    $updatedt = $myamount[$key]['updatedt'] == "0000-00-00 00:00:00" ? "" : date("m-d H:i", strtotime($myamount[$key]['updatedt']));
    if ($updatedt == "")
    {
        $updateid = "";
    }
    else
    {
        $updateid = $myamount[$key]['account'] == G_SUPERACCOUNT ? "─&nbsp;操盘" : "─&nbsp;" . $myamount[$key]['account'];
        $updateid .= $curruser['acl'] == 255 ? $myamount[$key]['updateid'] : "";
    }
    $tbdList = "<tr class=\"td2\">" . "<th class=\"bgClc_{$gametype}\" align=\"right\">{$value}</th>" . "<td><input size=\"6\" maxlength=\"6\" onkeypress=\"return OnlyFloat()\" class=\"tmpBack1\" name=\"back{$key}1\" value=\"" . round(100 - $myamount[$key]['back1'], 2) . "\"{$readonly}><span style=\"color:red\">(" . round(100 - $prev_amount[$key]['back1'], 2) . ")</sapn></td>" . "<td><input size=\"6\" maxlength=\"6\" onkeypress=\"return OnlyFloat()\" class=\"tmpBack2\" name=\"back{$key}2\" value=\"" . round(100 - $myamount[$key]['back2'], 2) . "\"{$readonly}><span style=\"color:red\">(" . round(100 - $prev_amount[$key]['back2'], 2) . ")</sapn></td>" . "<td><input size=\"6\" maxlength=\"6\" onkeypress=\"return OnlyFloat()\" class=\"tmpBack3\" name=\"back{$key}3\" value=\"" . round(100 - $myamount[$key]['back3'], 2) . "\"{$readonly}><span style=\"color:red\">(" . round(100 - $prev_amount[$key]['back3'], 2) . ")</sapn></td>" . "<td><input size=\"6\" maxlength=\"6\" onkeypress=\"return OnlyFloat()\" class=\"tmpBack4\" name=\"back{$key}4\" value=\"" . round(100 - $myamount[$key]['back4'], 2) . "\"{$readonly}><span style=\"color:red\">(" . round(100 - $prev_amount[$key]['back4'], 2) . ")</sapn></td>" . "<td><input size=\"6\" maxlength=\"11\" onkeypress=\"return OnlyInt()\" class=\"tmpAmount1\" name=\"amount1{$key}\" value=\"{$myamount[$key][1]}\"><span style=\"color:red\">({$prev_amount[$key][1]})</sapn></td>" . "<td><input size=\"6\" maxlength=\"11\" onkeypress=\"return OnlyInt()\" class=\"tmpAmount2\" name=\"amount2{$key}\" value=\"{$myamount[$key][2]}\"><span style=\"color:red\">({$prev_amount[$key][2]})</sapn></td>" . "<td class=\"bgClc_{$gametype}\">&nbsp;{$updatedt}&nbsp;{$updateid}</td>" . "</tr>";
    if (in_array($key, $listArr01))
    {
        $tbdList01 .= $tbdList;
    }
    else
    {
        $tbdList02 .= $tbdList;
    }
}
$tpl->set(array("tbdList1" => $tbdList01, "tbdList2" => $tbdList02, "disabled" => $edit_back_mode ? " disabled" : "", "total" => $total, "deletebutton" => $edit_back_mode ? "&#12288;※ 盘中禁止修改退水资料！ ※" : "", "submit" => 0 < $id ? "变更" : L_ADD, "url_reload" => "op.php?op=agent&fp=amount_3d&gametype={$gametype}&id={$id}", "gametype" => "bgClc_{$gametype}", "othertext" => $othertext, "action" => "?" . $_SERVER['QUERY_STRING'], "status" => $u['enabled'] == 0 ? "<span bgcolor='#000000'><font color='#ffffff'>停用</font></span>" : "<span bgcolor='#ffffff'>启用</span>", "op" => $op_val[$acl], "fp" => $fp_val[$acl], "account" => $u['account'], "name" => $u['name'], "id" => $id, "amount" => $u[$amountField], "getOptionList" => !$g_init_mode_3d ? "" : "<td>玩法切换</td><td class=td2>" . getOptionList($gametype, "op.php?op=agent&fp=amount_3d&id={$id}") . "</td>"));
$titleStr = $name_val[$acl] . ( 0 < $id ? L_EDIT : L_ADD ) . "&nbsp; " . $g_gametype_3d[$gametype]['ch'] . "&nbsp;单项限额";
echo title($titleStr, "<label>" . ( $edit_back_mode ? "【限额】最大值" : "【退水】【限额】最大值" ) . "<input type=\"checkbox\" value=\"1\" id=\"chkFast\" name=\"chkFast\" {$chkFastStr} /></label>&nbsp;&nbsp;&nbsp;" . $funlist, 900);
$tpl->show("main");
$ui->footer();
?>